<template>
  <div class="container">
    <img class="banner" src="@/assets/user-banner.png" alt="" />
    <div class="wrap">
      <div class="title">{{ info.title_cn }}</div>
      <div class="work">
        <span class="pointer" @click.prevent="download">
          <i class="el-icon-download"></i>下载
        </span>
        <img :src="info.image_url" alt="" />
      </div>
    </div>
    <payment ref="paymentRef" :isWechat="isWechat" />
  </div>
</template>

<script>
export default {
  name: "NavBar",
  components: {
    payment: () => import("@/components/payment.vue"),
  },
  data() {
    return {
      id: "",
      info: {},
      show: false,
      isWechat: false,
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    this.getInfo();
    this.isWechat = this.isWechatBrowser();
  },
  methods: {
    isWechatBrowser() {
      if (typeof navigator === "undefined") return false;
      // 检测 User-Agent 中是否包含 MicroMessenger
      return /MicroMessenger/i.test(navigator.userAgent);
    },
    getInfo() {
      this.$post("/index/images_detail", { image_id: this.id }).then((res) => {
        this.info = res.data;
      });
    },
    download() {
      //用户是否已购买过图
      this.$post("/user/download", { image_id: this.id }).then((res) => {
        if (res.code === 1) {
          window.open(res.data.url);
        } else if (res.code === 3) {
          this.$refs.paymentRef.open(this.id);
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
.banner {
  height: 300px;
}
.title {
  font-size: 58px;
  font-weight: bold;
  text-align: center;
  margin-top: 30px;
}
.content {
  text-align: center;
  color: #999;
  font-size: 16px;
  margin: 10px 0 40px;
}
.list {
  .col {
    padding: 10px 0;
    .item {
      position: relative;
      display: flex;
      &::before {
        content: "";
        height: calc(100% - 80px);
        width: 1px;
        background: #441054;
        position: absolute;
        left: 40px;
        bottom: 10px;
      }
      .date {
        width: 150px;
        font-weight: bold;
        font-size: 30px;
        color: #441054;
      }
      .content {
        width: calc(100% - 150px);
        img {
          max-width: 500px;
          height: 478px;
        }
        p {
          font-size: 16px;
          padding: 10px 0;
        }
      }
    }
  }
}

.work {
  position: relative;
  span {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba($color: #441054, $alpha: 0.5);
    border-radius: 3px;
    position: absolute;
    right: 0;
    top: 0;
    color: #fff;
    padding: 5px 10px;
    font-size: 14px;
  }
}
@media screen and (max-width: 768px) {
  .title {
    font-size: 24px;
  }
  .list .col .item .date {
    width: 60px;
    font-weight: bold;
    font-size: 18px;
    color: #441054;
  }
  .list .col .item .content {
    width: calc(100% - 60px);
    img {
      height: auto;
    }
  }
  .list .col .item .content p {
    font-size: 14px;
    padding: 10px 0;
  }
  .list .col .item::before {
    height: calc(100% - 60px);
    left: 26px;
  }
}
</style>
